<?php
namespace app\model;

use think\Model;

class Machine extends Model
{
    const IS_DELETE_NO = 0;
    const STATUS_NORMAL = 10;
    const STATUS_ABNORMAL = 20;

    public function checkExistByCode(int $factoryId, string $machineCode)
    {
        $info = $this->field('id')
            ->where('factory_id', $factoryId)
            ->where('machine_code', $machineCode)
            ->where('delete_time', self::IS_DELETE_NO)
            ->find();

        if (!$info) {
            return null;
        }

        return $info['id'];
    }

    //跟进id判断数据是否存在
    public function checkExistById(int $factoryId, int $machineId)
    {
        $info = $this->field('id')
            ->where('id', $machineId)
            ->where('factory_id', $factoryId)
            ->where('delete_time', self::IS_DELETE_NO)
            ->find();

        if (!$info) {
            return null;
        }

        return $info['id'];
    }
}